{# Copyright 2014-2017 Siemens AG

   Copying and distribution of this file, with or without modification,
   are permitted in any medium without royalty provided the copyright notice and this notice are preserved.
   This file is offered as-is, without any warranty.
#}
{% extends "include/base.html.twig" %}
{% block styles %}
  {{ parent() }}
  <link rel="stylesheet" href="css/highlights.css"/>
{% endblock %}

{% block content %}

<table class="semibordered" id="licenseCandidateTbl" width="100%" cellpadding="0">
  <thead>
    <tr><th width="5%"></th><th width="10%"></th><th width="15%"></th><th width="50%"></th><th width="10%"></th><th width="10%"></th></th></tr>
  </thead>
</table>
  <br/><br/>
  
{% endblock %}

{% block foot %}
  {{ parent() }}
  <script src="scripts/jquery.dataTables.min.js" type="text/javascript"></script>
  <script src="scripts/jquery.dataTables.select.js" type="text/javascript"></script>
  <script src="scripts/jquery-ui.js" type="text/javascript"></script>
  <script type="text/javascript">
    function createBrowseTable() {
      
    tableColumns = [
    {"sTitle": "{{ "Edit"|trans }}", "sClass": "center", "bSearchable": false},
    {"sTitle": "{{ "Shortname"|trans }}", "sClass": "center", "bSearchable": true},
    {"sTitle": "{{ "Fullname"|trans }}", "sClass": "center", "bSearchable": false},
    {"sTitle": "{{ "Text"|trans }}", "sClass": "left", "bSearchable": false},
    {"sTitle": "{{ "Group"|trans }}", "sClass": "center", "bSearchable": true},
    {"sTitle": "{{ "Delete"|trans }}", "sClass": "center", "bSearchable": false}
  ];

  tableSorting = [ [1, "asc"] ];

  dataTableConfig =
      {
        "aoColumns": tableColumns,
        "aaSorting": tableSorting,
        "iDisplayLength": 20,
        "aaData": {{ aaData }},
        "sPaginationType": "listbox",
        "bStateSave": true
      };

    var otable = $('#licenseCandidateTbl').dataTable(dataTableConfig);
    return otable;
  }
    
  function deleteCandidate(rfPk) {
    var mainDiv = "<div></div>";
    var confrimMessage = "Remove this license from candidate license list?";
    $(mainDiv).html(confrimMessage).dialog({
      title: "Please Confrim",
      resizable: false,
      modal: true,
      buttons: {
        "Ok": function() {
          $(this).dialog("close");
          $.ajax({
            type: 'POST',
            dataType: 'text',
            url: '?mod=admin_license_candidate&do=deletecandidate',
            data: { rf : rfPk },
            success: function(dataOnSuccess) {
              if(dataOnSuccess == "true"){
                $("#deletecandidate" + rfPk).closest("tr").hide();
              }else{
                $(mainDiv).html(dataOnSuccess).dialog({
                  title: "Cannot remove license, Because it is in use at",
                  width:'auto',
                  height:'auto',
                  modal: true,
                  buttons: {
                    "Close": function() {
                      $(this).dialog("close");
                    }
                  }
                });
              }
            },
            error: function() { alert('error'); }
          });
          },
        Cancel: function() {
          $(this).dialog("close");
        }
      }
    });
  }

  $(document).ready(function () {
    createBrowseTable();
  });
    
  </script>
{% endblock %}
